<?php if ($module != '') Yii::app()->layout = 'module'; ?>
<?php if (!empty($category)): ?>
<?php
echo FHtml::beginForm(array('/Core/category/save'), 'post', array('enctype'=>'multipart/form-data'));
FHtml::hightlightErrorFields();
echo FHtml::activeHiddenField($category,'Id');
echo FHtml::activeHiddenField($category, 'IsActive', array('value' => 1));
?>
    <h3>Edit category</h3>
    <div class="Input">
        <label for="Category_Title">Name (*): </label><a name="title"></a>
        <?php echo FHtml::activeTextField($category,'Title'); ?>
    </div>
    <div class="Input">
        <label for="Category_Description">Description: </label>
        <?php echo FHtml::activeTextArea($category,'Description', array('cols'=>48, 'rows'=>6)); ?>
    </div>
    
    <div class="Input">
        <label for="Category_Image">Image: </label><a name="title"></a>
        <?php 
        	echo FHtml::activeFileField($category, 'Image');
	        if (!empty($category->Image)) :
	    ?>
			    <div style="padding: 1em 0 0 160px;">
				    <img src="<?php echo BASEURL . '/image.php?thumb=' . $category->Image ?>" /> &nbsp;
				    <?php echo FHtml::link('Delete', $this->createUrl('deleteImage', array('categoryId' => $category->Id)), array('id' => 'lnkDeleteImage', 'name' => 'lnkDeleteImage')); ?>
			    </div>
			    
			    <script type="text/javascript">
			    	$('#lnkDeleteImage').click(function(){
						if (!confirm('Are you sure to delete this image')) {
							return false;
						}
			    	})
			    </script>
		<?php endif; ?>
    </div>
    <div class="Input">
        <label for="Category_ParentId">Parent Category (*): </label>
        <?php 
        
        // Get root category id
        if(!empty($module) && !empty($param)):
            eval("\$rootCategoryId = {$module}Settings::{$param}_CAT_ID;");            
            
        elseif(!empty($module)):
            eval("\$rootCategoryId = {$module}Settings::ROOT_CATEGORY_ID;");
            
        else:
            $rootCategoryId = null;
        endif;
        
        // Get selected value        
        if(is_null($category->Id)):
            $selectedItems = $rootCategoryId;
        else:
            $selectedItems = $category->ParentId;
        endif;
        
        $this->widget('CategoryDropdownWidget', array(
                                                        'Multiple' => false, 
                                                        'SelectedItems' => $selectedItems, 
                                                        'RootCategoryId' => $rootCategoryId,
                                                        'promptText'=>Yii::t('Category', 'NO_PARENT_CATEGORY')));
        ?>
    </div>
    <?php echo FHtml::hiddenField('OldParentId', $category->ParentId) ?>
    <?php echo FHtml::hiddenField('OldOrder', $category->Ordering) ?>
    <input type="hidden" value="<?php echo $module; ?>" id="module" name="module" />
    <input type="hidden" value="<?php echo $param; ?>" id="param" name="param" />

    <div class="Action">
        <?php echo FHtml::submitButton('Save'); ?>
        <?php echo FHtml::link('Cancel', array('/Core/category/list', 'module' => $module, 'param' => $param)); ?>        
    </div>

    <div class="requiredSymbolMeaning">(*) : <?php echo Yii::t('Category', 'REQUIRED_SYMBOL_MEANING'); ?></div>
    
<?php echo FHtml::endForm();?>
<?php
$cs = Yii::app()->ClientScript;
$cs->registerScriptFile(Yii::app()->theme->BaseUrl.'/scripts/common.js', CClientScript::POS_BEGIN);
endif; //!empty(category)
?>